Device-to-device (D2D) cooperative relay can improve network coverage and throughput by assisting users with inferior channel conditions to implement multi-hop transmissions. Due to the limited battery capacity of handheld equipment, energy efficiency is an important issue to be optimized. Considering the two-hop D2D relay communication scenario, this paper focuses on how to maximize the energy efficiency while guaranteeing the quality of service (QoS) requirements of both cellular and D2D links by jointly optimizing relay selection, spectrum allocation and power control. Since the four-dimensional matching involved in the joint optimization problem is NP-hard, a pricing-based two-stage matching algorithm is proposed to reduce dimensionality and provide a tractable solution. In the first stage, the spectrum resources reused by relay-to-receiver links are determined by a two-dimensional matching. Then, a three-dimensional matching is conducted to match users, relays and the spectrum resources reused by transmitter-to-relay links. In the process of preference establishment of the second stage, the optimal transmit power is solved to guarantee that the D2D link has the maximized energy efficiency. Simulation results show that the proposed algorithm not only has a good performance on energy efficiency, but also enhances the average number of served users compared to the case without any relay.