The emerging leading role of green energy in our society pushes the investigation of new economic and technological solutions. Green energies and smart communities increase efficiency with the use of digital solutions for the benefits of inhabitants and companies. The paper focuses on the development of a methodology for the energy management, combining photovoltaics and storage systems, considering as the main case study a multi-story building characterized by a high density of households, used to generate data which allow feasibility foresights. The physical model of the algorithm is composed by two main elements: the photovoltaics modules and the battery energy storage system. In addition, to gain information about the real-time consumption a machine learning module is included in our approach to generate predictions about the near future demand. The benefits provided by the method are evaluated with an economic analysis, which computes the return of the investment using the real consumptions of a Boarding School, located in Turin (Italy). The case study analyzed in this article showed an increase in purchased energy at the minimum price from 25% to 91% and a 55% reduction in the electricity bill compared to most solutions on the market, with no additional costs and a stabilizing effect on the grid. Finally, the economic analysis shows that the proposed method is a profitable investment, with a breakeven point of thirteen years, due to the very simple implementation and the zero additional cost requested.INDEX TERMS Deep learning, energy management systems, energy storage, environmental economics, renewable energy sources. FRANCESCO GRIMACCIA (Senior Member, IEEE) received the M.S. and Ph.D. degrees (cum laude) in electrical engineering from the Politecnico di Milano, Milan, Italy, in 2003 and 2007, respectively. He is currently an Associate Professor with the Energy Department, Politecnico di Milano. His main research interest includes softcomputing technique development and applications in different electric engineering fields, such as unmanned systems, photovoltaics, and other energy-harvesting devices. He is a member of the IEEE Computational Intelligence Society and the Vice-President of the Associazione Italiana di Elettrotecnica, Elettronica and the Automazione, Informatica e Telecomunicazioni, Milan Section.