Distributed Online Algorithms For Energy Management In Smart Grids