LoRaWAN has imposed itself as a promising and suitable technology for massive machine-type communications. With the acceleration of deployment, improving the energy efficiency of LoRaWAN networks has become paramount, especially with the limitations of throughput and battery resources. However, LoRaWAN suffers from the Aloha access scheme, which leads to a high probability of collision at large scales, especially in dense environments such as cities. In this paper, we propose EE-LoRa, an algorithm to improve the energy efficiency of LoRaWAN networks with multiple gateways via spreading factor selection and power control. We proceed in two steps, where we first optimize the energy efficiency of the network, defined as the ratio between the throughput and consumed energy. Solving this problem involves determining the optimal node distribution among different spreading factors. Then, in the second step, power control is applied to minimize the transmission power at nodes without jeopardizing the reliability of communications. The simulation results show that our proposed algorithm greatly improves the energy efficiency of LoRaWAN networks compared to legacy LoRaWAN and relevant state-of-the-art algorithms.