Smart grids are often analyzed using a top-down approach, i.e., starting from communication and control technologies evolution, to then focus on their effects on active and passive users, in terms of new services, higher efficiency and quality of supply. However, with their bottom-up approach, virtual power plants (VPP) are very promising instruments for promoting an effective integration of distributed generation (DG) and energy storage devices as well as valid means for enabling consumers to respond to load management signals, when operated under the supervision of a scheduling coordinator. These aggregation factors can be very profitable for the distributed energy resources (DERs) economy and for the energy network itself. This paper presents a new algorithm to optimize the day-ahead thermal and electrical scheduling of a large scale VPP (LSVPP) which contains: a) many small-scale producers and consumers ("prosumers") distributed over a large territory and b) energy storage and cogeneration processes. The algorithm also takes into account the actual location of each DER in the public network and their specific capability. Thermal and electrical generator models, load and storage devices are very detailed and flexible, as are the rates and incentives framework. Several novelties, with respect to the previous literature, are proposed. Case study results are also described and discussed.