In recent years, the access of many countries to microgrids has improved the quality and development of their economy. So far, a lot of research has been done in this regard. The results of this work show that there is a direct relationship between a country's level of development and its energy consumption. Many energy sources such as electricity and natural gas have so far been used separately. However, today, with the increased use and the advancement of production technologies, establishing a connection between energy systems has become a necessity. Therefore, energy sources are properly combined and integrated in order to increase the efficiency of the system. The use of combined heat and power and the presence of microgrids providing PV and wind energy in the network can effectively supply a part of the load. This paper considers linear programming, and smart home management based on connected microgrids to obtain electric and heating energy in a residential complex. The smart building is designed for 30 households with similar consumption habits. Next to each renewable source, a storage generator is considered which therefore constitutes an integrated resource. In order to protect the resources and observe their power limits, household appliances, demand response, charging, and discharging, and storage properties are taken into account in the problem. In order to manage equipment consumption, it is also necessary to adjust the performance interval, so that the cost for the consumer is optimized based on the hourly cost of power and the producer's profit. To this effect, the load profile of the complex is planned, and thus the cost functions under certain conditions. MATLAB tools for linear programming are used. We will see that for the four scenarios introduced, the total operating cost for the first scenario is ($)328.12, the second scenario is ($)267.54, the third scenario is ($)254.38, and the fourth scenario is the best cost with a value of ($)198.08. Also, the amount of CHP capacity has been examined based on different capacities from 5 kW to 100 kW.