Renewable Energy Communities (RECs) are an important building block for the decarbonization of the energy sector. The concept of RECs allows individual consumers to join together in local communities to generate, store, consume and sell renewable energy. A major benefit of this collective approach is a better match between supply and demand profiles, and thus, an increase in local self-consumption. The optimal exploitation of locally produced electricity raises many operational questions. In this context, we introduce a Mixed Integer Linear Program (MILP) that optimizes the energy flows within a REC. It employs the following instruments relevant for local self-consumption: (a) stationary batteries, (b) batteries of electric vehicles and (c) load shifting (i.e. moving the use of electric appliances from one time period to another). To handle the uncertainty of the involved planning parameters, we use a Model Predictive Control (MPC) approach and solve the optimization model in an iterative manner. The introduced planning framework can be applied to generate realistic performance measures of specific community configurations and to evaluate strategic investment decisions.