Nowadays, the shift towards renewable energies is happening at an exponential pace. Microgrids are an integral part in integrating renewable energies into the global energy mix. Due to the volatility of renewables, such as solar or wind, proper energy management is needed to avoid generation or load curtailment. This issue is addressed throughout the literature using a wide variety of strategies, ranging from classical linear to nature inspired metaheuristic optimization algorithms. This paper goes beyond the simulation phase of different optimization algorithms and addresses the optimal energy management problem by proposing a novel framework to integrate optimization strategies into the daily operation of microgrids. The proposed framework showcases 3 practical methods for controlling the distributed generators, as well as a communication scheme which facilitates the data transfer between the machine running the optimization strategy and the energy management system of the microgrid. The framework is demonstrated on a small-scale islanded microgrid setup, located at the Technical University of Cluj-Napoca. The microgrid setup consists of a photovoltaic array, a battery energy storage system and two dispatchable generators. A two-stage optimization strategy is used, consisting of a day-ahead stage, which uses the solar forecast provided by the Global Forecast System, prior to each day, to issue a working plan for the dispatchable generators, and an intra-day stage, which uses hourly solar forecasts, issued during the day, to adjust the operation of the microgrid and minimize the error between the day-ahead solar forecast and the actual weather conditions. Mixed integer linear programming is used to solve the optimization problem and validate the correct operation of the proposed framework over two case studies. The results show that the microgrid works as intended, in both scenarios, as well as the benefits of using an intra-day correction stage.