In order to narrow the gap between the requirements of IoT applications and the restricted resources of IoT devices and achieve devices energy efficiency, in this paper we design COMED, a novel mobile edge computing framework in ultra-dense mobile network. In this context, we propose an online optimization problem by jointly taking task offloading, base station (BS) sleeping and device-BS association into account, which aims to minimize the total energy consumption of both devicesand BSs, and meanwhile satisfies applications’ QoS. To tackle this problem, we devise an online Lyapunov-based algorithm JOSA by exploiting the system information in the current time slot only. As the core component of this algorithm, we resort to the loose-duality framework and propose an optimal joint task offloading, BS sleeping and device-BS association policy for each time slot. Extensive simulation results corroborate that the COMED framework is of great performance: 1) more than 30% energy saving compared with local computing, and on average 10%-50% energy saving compared with the state-of-the-art algorithm DualControl (i.e., energy-efficiency); 2) the algorithm running time is approximately linear proportion to the number of devices (i.e., scalability).