We propose learning and optimization algorithms for the next generation power systems. First, we design distributed algorithms to schedule the charging of electric vehicles. By implementing the algorithms, we obtain a favorable total load profile, while accounting for the capacity constraints induced by the power grid distribution lines and other components such as transformers. We further propose a novel algorithm for distributed charging control of electric vehicles using online learning. Many of the existing distributed charging control algorithms in the literature implicitly assume fast two-way communication between a distribution company and electric vehicle customers. This assumption may be impractical at present. Our algorithm does not impose such an assumption. The proposed algorithm requires one-way communication, which is implemented through the distribution company publishing the pricing profiles of the previous days. Second, we propose a distributed algorithm for online energy management in networked microgrids with a high penetration of distributed energy resources. In general, the state-of-the-art forecasting for distributed energy resources such as solar is not sufficiently accurate, which results in inaccurate energy scheduling. To address the high uncertainty issues, we propose an online energy management algorithm and use the historical data about the power generation from the distributed energy resources to proceed. The proposed energy management algorithm does not require the online algorithm to be fully executed, which further reduces the burden on the wireless communication spectrum usage.In the last part of this dissertation, we study the alternating current optimal power flow problem in the smart grids. In the alternating-current model, optimal power flow becomes a notoriously difficult non-convex non-linear optimization problem. We introduce two novel methods for solving the semidefinite programming relaxations of the alternating current optimal power flow problem in the literature. First, we present a method to include the block constraints from a higher-order semidefinite programming relaxation one-by-one, as required, to converge to the objective function value of the higher-order relaxation. Second, we present a method for solving the resulting semidefinite programming relaxations based on the block-coordinate descent method for the associated augmented Lagrangian.