The current energy strategy of the European Union puts the end-user as a key participant in electricity markets. The creation of energy communities has been encouraged by the European Union to increase the penetration of renewable energy and reduce the overall cost of the energy chain. Energy communities are mostly composed of prosumers, which may be households with small-size energy production equipment such as rooftop photovoltaic panels. The local electricity market is an emerging concept that enables the active participation of end-user in the electricity markets and is especially interesting when energy communities are in place. This paper proposes an optimization model to schedule peer-to-peer transactions via local electricity market, grid transactions in retail market, and battery management considering the photovoltaic production of households. Prosumers have the possibility of transacting energy with the retailer or with other consumers in their community. The problem is modeled using mixed-integer linear programming, containing binary and continuous variables. Four scenarios are studied, and the impact of battery storage systems and peer-to-peer transactions is analyzed. The proposed model execution time according to the number of prosumers involved (3, 5, 10, 15, or 20) in the optimization is analyzed. The results suggest that using a battery storage system in the energy community can lead to energy savings of 11-13%. Besides, combining the use of peer-to-peer transactions and energy storage systems can potentially provide energy savings of up to 25% in the overall costs of the community members.