The aim of the present work in this paper is to propose an optimized energy management strategy that allows enhancing the life cycle of batteries through the optimal scheduling of energy consumption in a house connected to a stand-alone energy system with an energy storage system (PV, wind turbine, diesel generator, and batteries). A rain flow counting algorithm is used to calculate the number of cycles of the battery, while the optimization problem was solved using a particle swarm optimization algorithm (PSO). The optimization aims to reduce the number of cycles in the whole day by managing the charging and discharging process in order to maximize the battery life cycle. The results obtained by the simulation prove the effectiveness of the proposed strategy in the optimization of the life cycle of the battery to more than 38%.