Microgrids (MG) in integration with distributed energy resources (DERs) are one of the key models for resolving the current energy problem by offering sustainable and clean electricity. This research presents a novel approach to address the complex challenges of optimizing a DERs based microgrid while considering multiple objectives. In this paper, the utilization of a popular machine learning algorithm, random forest (RF) model is proposed to optimize the DERs based MG configuration. The research commences by collecting historical data on energy consumption, renewable energy production, electricity prices, weather conditions, and other relevant factors of Bengaluru City (Karnataka, India) for different seasons. This research covers the conflicting objectives by finding optimal seasonal sizing of the battery, minimum generation cost, and reduction in battery charging cost. The optimization and analysis are done using an ensemble learning-based RF model. The findings from the RF model are compared with meta-heuristics and artificial intelligence (AI) methods such as particle swarm optimization (PSO) and artificial neural networks (ANN) for different seasons, i.e., winter, spring and autumn, summer, and monsoon.