Hierarchical control framework to exploit community energy storage for both local and system benefit