Dual mode operation capability of distributed energy resources in microgrids is an attractive feature that makes these systems a promising solution for improving reliability and economy of the power system. However, the transition between microgrid operation modes (grid-connected and islanding) may lead to a significant deviation in voltage and current because of inconsistency in phase, frequency, and voltage amplitude. To minimize the fluctuations and provide a smooth transition, this paper presents an optimal control framework based on linear quadratic regulator. The framework includes two regulators that separately designed for each transition mode: 1) grid-connected to islanding smooth regulator, and 2) islanding to grid-connected smooth regulator. Optimality based on optimizing solution, smooth transition, ease of implementation due to its simple state feedback form and compatibility with familiar cascade loops are the main advantages of the proposed approach. Experimental results are presented to validate the efficacy of the proposed approach.