Predictive Control of Multilevel Inverters using Online and Offline Optimization