To meet the demand of green communications of ultradense mobile devices (MDs), an energy-efficient mechanism, jointly considering the computation offloading and resource management, is designed to minimize the network-wide weighted energy consumption under the delay constraints of MDs for ultradense heterogeneous networks. Such a mechanism tightly integrates with the adjustment of computation capability and transmission power of MDs. Considering that the finally formulated problem is in a nonlinear and mixed-integer form, we design an effective algorithm to solve it. Specifically, by utilizing the powerful global searching capability of genetic algorithm (GA) and the accurate local searching capability of particle swarm optimization (PSO), the adaptive GA with diversity-guided is firstly used for coarse-grained search, and then adaptive PSO is utilized for fine-grained search. After that, some detailed analyses on the convergence, computation complexity and parallel implement are provided for algorithms. Simulation results show that the designed algorithm can achieve a lower network energy consumption than other offloading algorithms in general. At the same time, the numerical simulation also reveals that the designed algorithm may be more suitable for ultradense networks than existing algorithms.