This article discusses how to use optimization-based methods to efficiently operate microgrids with a large share of renewables. We discuss how to apply a frequency-based method to tune the droop parameters in order to stabilize the grid and improve oscillation damping after disturbances. Moreover, we propose a centralized real-time feasible nonlinear model predictive control (NMPC) scheme to achieve efficient frequency and voltage control while considering economic dispatch results. Centralized NMPC for secondary control is a computationaly challenging task. We demonstrate how to reduce the computational burden using the Advanced Step Real-Time Iteration with nonuniform discretization grids. This reduces the computational burden up to 60 % compared to a standard uniform approach, while having only a minor performance loss. All methods are validated on the example of a 9-bus microgrid, which is modeled with a complex differential algebraic equation.