The aim of this work was to develop an optimal model for an energy management strategy in a real micro-grid, which involves a smart building, a photovoltaic system with storage, and a plug-in full electric vehicle. A controller based on a mathematical algorithm was the core of each strategy, which directly acted on a relay board managing the interconnection between the different elements comprising the micro-grid. The development of an optimization model involving binary variables required an efficient code that achieved solutions in a short time. The analyzed case-study corresponded to the solar energy research center (CIESOL) smart building, a bioclimatic building, that is located at the University of Almería (Spain), designated to research in renewable energies. Using the methodologies described in this work, the total cost of the smart building energy consumption was minimized by decreasing the power supplied from the grid, especially at peak hours. Highlighting the use of a simple model that provided better performance than the current state of the art methodologies. The optimal model for energy management strategy demonstrated the advantages of using classical optimization techniques to solve this specific optimization problem, compared to a rule-based controller. The linear modeling was capable of producing a simple algorithm with less code development and a reduction in the computational effort.