The scientific community believes that peer-to-peer energy trading will dominate a significant portion of forthcoming power generation systems research. Despite a plethora of optimal energy trading solutions, optimizing the trading cost and intelligent formation of energy sharing strategies are deemed exigent problems. Contemplating the excessive rise of energy demands across the globe, this study introduces a predictive optimization-based nanogrid energy trading model that minimizes energy trading cost and provides an optimal energy sharing plan between peers connected within a nanogrid network/cluster. The proposed study comprises two folds: (1) PSO-enabled objective function incorporating actual and predicted values of essential energy attributes, is implemented to reduce the trading cost, (2) an intelligent time-aware energy sharing strategy to determine the role of peers, and foster the harness of renewable energy to meet the energy requirements. The study also comprehensively analyzes essential nano-grid energy parameters and predicts energy load, consumption, and cost to grasp the time-interval-based energy trends. In addition, an optimal ESS charging and discharging operation is devised to manage excess power efficiently. The proposed model is validated on the case study containing data of 12 nanogrid houses. The outcomes yield that the proposed study holds significant potential in reducing the trading cost and optimally sharing the energy within the P2P network.