According to the cogeneration characteristics of proton exchange membrane fuel cell and electrolyzer, in order to avoid the waste of heat energy in the hydrogen energy system and further improve the system efficiency, a combined heat–power microgrid system for photovoltaic, wind turbines, fuel cells, batteries, electric boilers, and gas boilers is built by incorporating hydrogen energy system, and a two-stage optimal dispathing method is proposed, including day-ahead scheduling and real-time optimization. The proposed system takes into account the waste heat recovery during the electricity-to-hydrogen conversion, and uses the hydrogen energy system as a thermal-electricity-hydrogen coupling equipment to realize the coordinated utilization and mutual conversion of electricity, heat, and hydrogen energy, and effectively improves the energy utilization rate. In the first stage of scheduling, according to the forecast of the wind-solar power system output and load demand in the day before, the mixed integer linear programming method is used to achieve the day-ahead optimal global schedule with the goal of minimizing the total operation cost of the microgrid. In the second stage of scheduling, based on the results of ultra-short-term predictions, the mixed integer quadratic programming algorithm is embedded in the model predictive control to lessen the economic influence from the prediction errors. Finally, through calculation examples of typical days in winter, summer and transitional seasons, compared with the day-ahead global optimal scheduling, the total cost of the two-stage scheduling method is reduced by 3.24%, 0.76% and 1.66%, respectively, in three types of seasonal days. Through the proposed method are simulated and verified in different scenarios, compared with the basic scenario without energy coupling, in the cases of involving the thermoelectric hydrogen coupling system and thermoelectric coupling system, the total cost and cost of pollution gas treatment with optimal scheduling are reduced by 15.58% and 24.93% respectively. The results show that the proposed method has a real-time and universal quality, which can meet the thermal and electrical load demand in the microgrid, realize stable and independent operation, and improve the system economy and environmental protection.