Peer-to-peer (P2P) trading is essential in maximising the benefits of renewable integration. The paper proposes a novel framework for economic benefit through P2P trading among buildings at different geographical locations. The number of transactions is reduced by grouping the buildings into virtual communities (VCs) based on their geographical locations. A non-cooperative game is formulated and solved in a decentralised manner for the energy management of individual buildings, building-tobuilding (B2B) energy exchange, building-to-community (B2C) energy exchange, energy management of the respective VC, and community-to-community (C2C) energy exchange. Load shifting is used to incorporate demand-side management. Cloud computing-based proposed algorithm is used for determining the energy profile and prices for each internal transaction (B2B, B2C, and C2C) separately to encourage the participation of each building by benefiting them appropriately and avoiding privacy/security issues normally arising in any data-centric framework. A shareable battery energy storage system (BESS) is also assumed to be present in each VC. Load shifting is used in the modelling of buildings to incorporate demandside management.INDEX TERMS BESS, Decentralised optimisation, Demand response, Generalised Nash Equilibrium, Peer-to-Peer energy sharing Nomenclature n,i,j,h Power imported by building i from building i and the respective payment P b2c n,i,h ,π b2c n,i,h Power imported by building i from its VC n and the respective payment P c2c n,m,h ,π c2c n,m,h Power imported by VC n from VC m and the respective payment P ch n,h ,P dis n,h Charging/discharging power of battery P b n,i,h ,P s n,i,h Power import/export from/to utility P ls n,i,h ,L n,i,h Shifted load and Actual load respectively P max n,i ,P min n,i Power exchange limit of building i from VC n P chmax n ,P chmin n Maximum/minimum limit for charging power of the battery of VC n P dismax n ,P dismin n Maximum/minimum limit for discharging