Resource Allocation And Control In Communication And Cyberphysical Networks With Renewable Energy