Résumé : This thesis explores the multifaceted challenges of security and privacy within smart gridsand energy communities, emphasizing the integration of community energy systems thatfoster renewable energy. The research delves into the intricate technologies and infrastructures that constitute smart grids and energy communities, examining how these systemsmanage communication, production, and consumption of energy. A significant portion ofthe study is dedicated to identifying and evaluating the unique threats and vulnerabilitiesspecific to energy communities, employing the STRIDE methodology for a systematic riskassessment. Furthermore, the thesis proposes robust threat models and mitigation strategies tailored to these communities, aiming to enhance their resilience against potentialcyber threats.The work assesses the efficacy of current security frameworks and identifies gaps in theexisting approaches to safeguarding these critical infrastructures. The contributions ofthis research lie in its detailed analysis of the technological underpinnings of smart gridsand energy communities, the development of comprehensive threat models, and the formulation of actionable mitigation strategies. These elements collectively advance the stateof the art in securing community-based energy systems, thereby supporting the broadergoals of sustainable development in energy management.The findings are intended to aid stakeholders involved in the design, operation, and governance of smart grids and energy communities in implementing more secure and privacyconscious energy solutions. The thesis underscores the importance of integrating robustsecurity measures in the early stages of system design to prevent future vulnerabilities,thereby facilitating a safer transition towards sustainable and community-driven energysolutions.