In the residential area, the cost of the electricity is at the maximum level during the peak demand periods. Regarding this, the peer-to-peer (P2P) energy trading strategy is a hopeful and practical solution to deal with this problem. Also, in the P2P home energy management system, the buildings have become more flexible by sharing their powers to meet their electricity demands. In this work, we have considered three buildings, in which two of them are equipped with solar panels, and in the third one, the hydrogen source is established. In the proposed residential zone, the considered buildings are connected in order to perform P2P transactions to reduce the energy billing. The operator of the system is wholly investigated under uncertain conditions based on the downside risk constraint (DRC) method in both risk-averse and risk-neutral models. With the help of a P2P energy trading strategy as well as renewable energy resources, we can provide electricity to customers in remote areas where it is not possible to supply electricity or is not economically beneficial. Based on the obtained results, the function of the proposed system has manifested in an acceptable manner. For instance, in the solar panel function in the second building, the amount of generated solar power is 30 kW in the risk-averse model, whereas, in the risk-neutral model, it is 18 kW. On the other hand, the level of consumed electricity by the electrolyzer system is generally lower in the risk-averse model than risk-neutral model in the second season.