The invention discloses an optimization method for minimizing energy consumption and time delay sum in edge calculation. The optimization method comprises the following steps of 10) performing initialization operation on an edge server; 20) calculating the optimal power of cellular users in all NOMA groups, and randomly selecting N NOMA groups; 30) randomly matching the N NOMA groups with D2D pairs one by one by using an edge server, and calculating a utility function; 40) executing a pre-exchange operation by using the edge server; 50) calculating a utility function by utilizing the edge server, judging whether an exchange condition is met or not, if so, executing an exchange operation, and returning to the step 40); and if not, judging whether a D2D pair capable of executing the pre-exchange operation exists or not, if not, ending iteration, and if yes, returning to the step 40). According to the method, the purpose of minimizing the energy consumption and the time delay sum of a honeycomb and a D2D user in the migration process can be achieved.