This paper proposes an energy management system to achieve an optimal power flow that minimizes the total economic cost associated with the monthly energy consumption of a five-apartment residential building. The test has considered that each apartment has one electric vehicle, and the building has an energy storage system in the lower plant and a solar photovoltaic generation system on the rooftop. The aim is to provide residential users with guidelines on the times of the day to charge their electric vehicles and the amount of energy to charge each hour in a lower monthly energy bill. The optimization problem regarding economic cost minimization is solved using a particle swarm optimization algorithm. Thus, three cases defined as the consumption of residential users at different day hours are employed to test the method proposed. Simulation results show that the algorithm reduces the energy bill of a typical residential user up to 20.08% compared to a user whose patterns of electric vehicle chargers are not optimized. Additionally, the comparison of the results obtained for the three types of residential users has allowed the establishment of the ideal residential user that guarantees the lowest energy bill possible.