In order to exploit the potential of local electricity generation from photovoltaic systems on multi-family houses or in urban areas, the first pilot projects of tenant electricity models (\grqq Mieterstrommodell\grqq) are currently being implemented. The logical next step is the extension of this concept to several buildings, the so-called energy community. Thereby resulting synergy effects through holistic consideration of individual load profiles can be increasingly exploited. This diploma thesis does therefore deal with the peer-to-peer electricity trading within an energy community under consideration of different ecological and economical preferences of the participants. For this purpose, an optimization model is developed in Matlab, which optimally distributes the locally generated electricity (from photovoltaics) through peer-to-peer trading within the energy community. An optimum for the individual participants is achieved when electricity is purchased at minimum cost or sold with maximum income. Furthermore the prosumers are modelled with different willingness to pay. These are influenced by an individual weighting factor accounting for emissions in the interconnected electricity grid as well as the spatial distance between two potential trading partners. According to the results, the internal electricity trade leads to a similarly high local self-consumption within the entire energy community as battery storages do. The individual preferences of the prosumers, expressed by their willingness to pay, determine the traded electricity. For example, particularly ecologically motivated participants can obtain a larger share of internally traded electricity than exclusively economically motivated participants. In addition, case studies show that differences in electricity demands, load profiles or the distribution and size of photovoltaic systems within the energy community contribute positively to the total volume of electricity traded. If, for example, businesses with high electricity consumption are integrated into the energy community, both the local electricity producers and the companies themselves benefit and more locally generated electricity is traded overall. However, the legal basis for such peer-to-peer electricity trading must first be created.