In this study, the techno-economic potential and optimal configuration are investigated under various renewable energy (RE)-based, stand-alone and grid-connected microgrid scenarios. HOMER software is employed to assess the physical, operating, and economic performance of the system’s components, and to obtain the most cost-effective configuration pattern. The outputs obtained from the case study for a residential community in Beijing can help the decision maker identify the optimal adoption of renewable energy sources, electricity generation, and economic benefits. Results show that there is a very high potential for applying a predominantly RE-based microgrid in a residential community in Beijing, which could supply at least 90% of the onsite electricity demand with 47–100% RE sources. In the grid-connected model, the total net present cost (TNPC) of the microgrid system would be, at most, 57% of the obtained electricity less than that completely from the external grids. Results also indicate that it would be more cost-effective when wind power becomes the main energy source and combined with moderately capacity of solar photovoltaic (PV) in the RE hybrid microgrid system. Additionally, a system with moderate size of batteries tends to be more ecologically friendly and cost-effective both in the stand-alone and grid-connected models than a system without batteries.