This study presents peer-to-peer (P2P) energy transaction mechanisms to maximize social welfare considering the uncertainty and profit fairness of the players. The P2P energy transaction problem is formulated as a P2P energy transaction pair matching and the determination of the P2P transaction price. To solve the problem, the optimal condition to maximize social welfare is determined using stochastic P2P energy transaction performance analysis based on the uncertainty characteristics. The analysis results show that social welfare is maximized to match the producer and consumer pairs that have similar demand characteristics; the P2P transaction price balances the profit fairness between the pair. Using these results, two centralized P2P energy transaction mechanisms are proposed by modifying the optimization problem. Moreover, a decentralized P2P energy transaction mechanism that operates in a distributed manner is suggested with the operational signal flow for the implementation of the mechanism. The simulation results show that the centralized and decentralized mechanisms have near optimal performance, with less than a 0.5% and 1% optimal gap compared to the optimal solution that requires perfect information including uncertainty, respectively. However, the decentralized mechanism is less computationally complex and uses less information than the centralized mechanisms; consequently, it can alleviate the operational burden and security and privacy problems. In addition, the results show that the performance of P2P energy transaction is related to the relative demand ratio between the producer and consumer. The optimal condition and results suggest a guide to the design of the P2P energy transaction. INDEX TERMS Demand-side management, distributed energy transaction, distributed generation, energy community, energy trading, fairness, peer-to-peer, prosumer, uncertainty.