To avoid transient jumps at the switching time between two operating modes in microgrids, this paper proposes a linear quadratic-based optimal bumpless controller with two degrees of freedom (DOF) to suppress the transient disturbance and realize seamless switching between mode-dependent controllers. By minimizing the transient performance criteria, which contains both the reference tracking error and the controller tracking error, this bumpless algorithm not only effectively forces the latent controller to track the active controller, but also guarantees the plant output track the reference as close as possible. For the different control objectives of the two modes, a current-based networked PI controller is proposed in islanded mode to achieve power sharing, as well as suppressing circulating current, and a power-based PI controller is designed in grid connected mode to supply required P and Q, as well as effectively synchronize f and v safely with the main grid. A microgrid test system with two operation modes was built in Matlab/Simulink. Several operating cases were executed to verity the feasibility and effectiveness of this optimal bumpless control strategy.