This study introduces an advanced Mixed-Integer Linear Programming model tailored for comprehensive electrical and thermal energy management in small-scale smart grids, addressing emergency load shedding and overload situations. The model integrates combined heat and power sources, capable of simultaneous electricity and heat generation, alongside a mobile photovoltaic battery storage system, a wind resource, a thermal storage tank, and demand response programs (DRPs) for both electrical and thermal demands. Power-to-hydrogen systems are also incorporated to efficiently convert electrical energy into heat, enhancing network synergies. Utilizing the robust Gurobi solver, the model aims to minimize operating, fuel, and maintenance costs while mitigating environmental impact. Simulation results under various scenarios demonstrate the model’s superior performance. Compared to conventional evolutionary methods like particle swarm optimization, non-dominated sorting genetic algorithm III, and biogeography-based optimization, the proposed model exhibits remarkable improvements, outperforming them by 11.4%, 5.6%, and 11.6%, respectively. This study emphasizes the advantages of employing DRP and heat tank equations to balance electrical and thermal energy relationships, reduce heat losses, and enable the integration of larger photovoltaic systems to meet thermal constraints, thus broadening the problem’s feasible solution space.