Intelligent networks for producing and storing electricity and heat