One of the main features of microgrids is the capability of operating in both grid-connected (GC) and standalone (SA) modes. This paper presents a novel dual mode robust model predictive control (RMPC) strategy for a three-phase inverter with an LCL filter in both GC and SA operating modes under the filter’s parameter uncertainty. At first, a disturbance observer gain is obtained by solving a linear matrix inequality (LMI), which is determined to preserve the stability of the algorithm. The designed disturbance observer takes into account the polytopic uncertainty of system parameters. A performance index with two weighting matrices is then defined and solved in an infinite horizon by turning it into an optimization problem under LMI constraints. The performance of the control strategy highly depends on the weighting matrices. Hence, an optimization algorithm is formulated to ascertain the best matrices values for both GC and SA operation modes. Given the nonlinearity issue, particle swarm optimization (PSO) is employed to derive the optimal weighting matrices offline. To evaluate the proposed control strategy’s effectiveness, simulations and experiments are performed under several scenarios in both GC and SA operating modes. The results reveal the proposed control strategy’s powerfulness compared to other techniques in the presence of grid voltage and load current disturbances for both inverter operating modes.