The energy efficiency (EE) of Device-to-Device (D2D) communication underlay cellular networks has become a significant issue because of increasing the resource utilization and extending the battery life of user equipment. However, the interference caused by sharing the same resources with the cellular users will descend the performance of the system. Therefore, D2D users should be allocated reasonable sub-carrier and suitable power to improve the performance of the cellular networks. In this paper, D2D communication can directly transmit information or transmit dates through an assisted relay based on the outage probability of D2D users. Meanwhile, we propose an algorithm to study the problem of EE of D2D communication under the condition of the required QoS (Quality of Services) of both cellular users and D2D users and the maximum transmission power threshold of D2D users. To solve the problem efficiency, we divide the algorithm into two stages to allocate sub-carrier and optimize power, respectively. By numerical simulation, we also prove the good performance of the proposed algorithm.