In this paper the optimal operation scheduling of a microgrid laboratory system consisting of a wind turbine, a solar unit, a fuel cell and two storage battery banks is formulated as an optimization problem. The proposed optimization algorithm considers the minimization of active power losses. Due to this type of variable, the problem is formulated as a Mixed-Integer Quadratic Programming model (MIQP) and solved by a deterministic optimization technique implemented in General Algebraic Modeling System (GAMS). This algorithm has been used as Virtual Power Producer (VPP) software to operate the generation units and storage system, assuring a global functioning of all equipment efficiently, taking into account the maintenance, operation and the generation measurement and control considering all involved costs. The VPP software has been implemented in a mini Supervisory Control and Data Acquisition (SCADA) system and controls the microgrid laboratory via Programmable Logic Controllers (PLC) devices. The application of this methodology to a real case study of the laboratory equipment demonstrates the effectiveness of this method for solving the optimal dispatch and online control of a microgrid, encouraging the application of this methodology for larger power systems.