The impact of environmental regulations introduced by the European Union is of key importance for electricity generation systems. The Polish fuel structure of electricity production is based on solid fuels. Moreover, the generating base is outdated and must gradually be withdrawn from the power system. In this context, Poland’s energy policy is undergoing a transformation as climate and environmental regulations are becoming increasingly stringent for the energy sector based on solid fuels (hard coal and lignite). However, the transformation process must be adapted to market demands, because the overriding goal is to ensure energy security by maintaining the continuity of energy supplies and an acceptable electricity price. This directly contributes to the development of the entire economy and the standard of living of the society, in accordance with the European Agreement establishing an association between the Republic of Poland and the European Communities and their Member States, signed on 16 December 1991, and the European Energy Charter, signed on 17 December 1991. Ensuring energy security is the most important goal of the energy policy. Therefore, energy companies must forecast the demand. The main goal of this article is to develop a mathematical model of electricity consumption by 2040 by all sectors of the economy: industry, transport, residential, commercial and public services, agriculture, forestry, and fishing. In order to achieve the intended goal, a model was developed by using Long Short-Term Memory (LSTM) artificial neural networks, which belong to deep learning techniques and reflect long-term relationships in time series for a small set of statistical data. The results show that the proposed model can significantly improve the accuracy of forecasts (1–3% of mean absolute percentage error (MAPE) for the analyzed sectors of the economy).