The operation of microgrids, i.e., energy systems composed of distributed energy generation, local loads and energy storage capacity, is challenged by the variability of intermittent energy sources and demands, the stochastic occurrence of unexpected outages of the conventional grid and the degradation of the Energy Storage System (ESS), which is s. ••The problem is joint optimization of operation and maintenance.••The method is based on deep reinforcement learning.••It is applied to a grid connected microgrid.••Battery degradation and occurrence of main grid outages are considered.••The optimal solution found significantly outperforms state-of-the-art strategies.MicrogridEnergy storage systemsOperation and maintenanceOptimizationCI Computational IntelligenceCM Corrective MaintenanceDNN Deep Neural NetworkDP Dynamic ProgrammingDRL Deep Reinforcement LearningEMS The global energy demand is expected to increase by 50% by 2050 and the energy produced from Renewable Energy Sources (RESs) is required to increase by 12% every year to satisfy the demand, while meeting the challenging goals related to the reduction of the environmental impact of climate change. MicroGrids (MGs) are one of the possible alternatives to efficiently include RESs in the main utility grid. An MG is a small-scale power entity which includes local loads, RESs-based distributed energy generation, such as PhotoVoltaic (PV) modules and wind turbines, and Energy Storage Systems (ESSs), e.g., lithium-ion batteries.MGs allow utilities to maintain the grid balance, reducing the load peaks and transmission energy losses, and enhance the grid resilience against unexpected events such as natural disasters [4,5]. Also, MGs allow customers playing an active role in the electricity market by controlling, scheduling and managing their own loads. Despite all these advantages to utilities and customers, the integration of RESs in MGs is challenged by the large variability of energy production from RESs and energy demand, which makes it difficult to plan accurate energy generation schedules. For coping with this problem, the ESS is fundamental to guarantee the reliability of the energy supply, since it can store the surplus of energy produced during periods of high RESs availability.