Recent advancements in sensor technologies have significantly improved the monitoring and control of various energy parameters, enabling more precise and adaptive management strategies for smart microgrids. This work presents a novel model of an energy management system (EMS) for grid-connected polygeneration microgrids that allows optimizing the management of electrical storage systems, electric vehicles, and other deferrable loads such as heat pumps. The main novelty of this model is that it incorporates both climate comfort variables and the consideration of the degradation of the energy storage capacity in the control strategy, as well as a penalty for the dumping of surpluses. The model has been applied to a smart, sustainable building as a case study. The results show that the proposed model is highly adaptable to diverse weather conditions, minimizing renewable energy losses while satisfying the energy demand and providing comfort to the building’s users. The study shows (i) that EVs’ dynamic charging schedules play a crucial role, (ii) that it is possible to minimize a battery’s degradation by optimizing its cycling, averaging one cycle per day, and (iii) the critical impact of seasonal weather patterns on microgrid energy management and the strategic role of EVs and storage systems in maintaining energy balance and efficiency.