This paper presents an algorithm for reducing the operating cost of microgrids. The proposed algorithm determines the day-ahead microgrid scheduling and builds a fuzzy expert system to control the power output of the storage system. To perform such tasks, two genetic algorithms were employed. One of them generates the microgrid scheduling and determines the fuzzy rules of the expert system, whereas the other is used to tune the membership functions. In this way it is possible to optimize the expert system according to load demand, wind power availability and electricity prices. Simulations were carried out in a microgrid comprising a diesel generator, a microturbine, a fuel cell, a wind turbine and a battery. Both interconnected and island operation modes were considered. Simulation results verify the effectiveness of the proposed algorithm.