Electricity demand in residential areas is generally met by the local low-voltage grid or, alternatively, the national grid, which produces electricity using thermal power stations based on conventional sources. These generators are holding back the revolution and the transition to a green planet, being unable to cope with climatic constraints. In the residential context, to ensure a smooth transition to an ecological green city, the idea of using alternative sources will offer the solution. These alternatives must be renewable and naturally available on the planet. This requires a generation that is very responsive to the constraints of the 21st century. However, these sources are intermittent and require a hybrid solution known as Hybrid Renewable Energy Systems (HRESs). To this end, we have designed a hybrid system based on PV-, wind-turbine- and grid-supported battery storage and an electric vehicle connected to a residential building. We proposed an energy management system based on nonlinear programming. This optimization was solved using sequential quadrature programming. The data were then processed using a long short-term memory (LSTM) model to predict, with the contribution and cooperation of each source, how to meet the energy needs of each home. The prediction was ensured with an accuracy of around 95%. These prediction results have been injected into K-nearest neighbors (KNN), random forest (RF) and gradient boost (GRU) repressors to predict the storage collaboration rates handled by the local battery and the electric vehicle. Results have shown an R2_score of 0.6953, 0.8381, and 0.739, respectively. This combination permitted an efficient prediction of the potential consumption from the grid with a value of an R²-score of around 0.9834 using LSTM. This methodology is effective in allowing us to know in advance the amount of energy of each source, storage, and excess grid injection and to propose the switching control of the hybrid architecture.