This paper presents an algorithm for economic optimization of a laboratory microgrid. The microgrid incorporates a hybrid storage system composed of a battery bank and a hydrogen storage and it has a connection with the external electrical network and a charging station for electric vehicles. To study the impact of use of renewable energy power systems, the microgrid has a programmable power supply that can emulate the dynamic behavior of a wind turbine and/or a photovoltaic field. The system modeling was carried out using the Energy Hubs methodology. A hierarchical control structure is proposed based on Model Predictive Control and acting in different time scales, where the first level is responsible for maintaining the microgrid stability and the second level has the task of performing the management of electricity purchase and sale to the power grid, maximize the use of renewable energy sources, manage the use of energy storages and perform the charge of the parked vehicles. Practical experiments were performed with different weather conditions of solar irradiation and wind. The results show a reliable operation of the proposed control system.