Control and optimization of distributed energy resources using dynamic algorithms