Federated Learning (FL) has emerged as a powerful model for training collaborative machine learning (ML) models while maintaining the privacy of participants’ data. However, traditional FL methods can exhibit limitations such as increased communication overhead, vulnerability to poisoning attacks, and reliance on a central server, which can impede their practicality in certain IoT applications. In such cases, the necessity of a central server to oversee the learning process may be infeasible, particularly in situations with limited connectivity and energy management. To address these challenges, peer-to-peer FL (P2PFL) offers an alternative approach, providing greater adaptability by enabling participants to collaboratively train their own models alongside their peers. This paper introduces an original framework that combines P2PFL and Homomorphic Encryption (HE), enabling secure computations on encrypted data. Furthermore, a defense approach against poisoning attacks based on cosine similarity is introduced These techniques enable users to collectively learn while preserving data privacy and accounting for ideal energy optimization. The proposed approach has demonstrated superior performance metrics in terms of accuracy, F-scores, and loss when compared to other similar approaches. Furthermore, it offers robust privacy and security measures, leading to an enhanced security level, with improvements ranging from 5.5% to 14.6%. Moreover, we demonstrate that the proposed approach effectively reduces the communication overhead. The proposed approach resulted in impressive reductions in communication overhead ranging from 63.8% to 79.6%. The implementation of these security models was cumbersome, but we have made the code publicly available for your reference 1.