This study presents a new two-stage hybrid optimization algorithm for scheduling the power consumption of households that have distributed energy generation and storage. In the first stage, non-identical home energy management systems (HEMSs) are modeled. HEMS may contain distributed generation systems (DGS) such as PV and wind turbines, distributed storage systems (DSS) such as electric vehicle (EV), and batteries. HEMS organizes the controllable appliances considering user preferences, amount of energy generated/stored and electricity price. A group of optimum consumption schedules for each HEMS is calculated by a Genetic Algorithm (GA). In the second stage, a neighborhood energy management system (NEMS) is established based on Bayesian Game (BG). In this game, HEMSs are players and their pre-determined optimal schedules are their actions. NEMS regulates the total power fluctuations by allowing the energy transfer among households. In the proposed algorithm, HEMS decreases the electricity cost of the users, while NEMS flats the load curve of the neighborhood to prevent overloading of the distribution transformer. The proposed HEMS and NEMS models are implemented from scratch. A survey of 250 participants was conducted to determine user habits. The results of the survey and the proposed system were compared. In conclusion, the proposed hybrid energy management system saves power by up to 25% and decreases cost by 8.7% on average.