Long Range (LoRa) communications, operating through the LoRaWAN protocol, have received increasing attention from the low-power and wide-area network communities. Efficient energy consumption and reliable communication performance are critical aspects of LoRa-based applications. However, current scientific literature tends to focus on minimizing energy consumption while disregarding channel changes affecting communication performance. Other works attain appropriate communication performance without adequately considering energy expenditure. To fill this gap, we propose a novel solution to maximize the energy efficiency of devices while considering the desired network performance. This is done using a maximum allowed Bit Error Rate (BER) that can be specified by users and applications. We characterize this problem as a Markov Decision Process and solve it using Deep Reinforcement Learning to dynamically and quickly select the transmission parameters that jointly satisfy energy and performance requirements over time. Moreover, we support different payload sizes, ensuring suitability for applications with varying packet lengths. The proposed selection of parameters is evaluated in three different scenarios by comparing it with the traditional Adaptive Data Rate (ADR) mechanism of LoRaWAN. The first scenario involves static nodes with varying BER requirements. The second one realistically simulates urban environments with mobile nodes and fluctuating channel conditions. Finally, the third scenario studies the proposed solution under dynamic frame payload length variations. These scenarios cover a wide range of operational conditions to ensure a comprehensive evaluation. The results of our experiments demonstrate that our proposal achieves a 60% improvement in performance metrics over the default ADR mechanism.