In electrical distribution grids, the constantly increasing number of power generation devices based on renewables demands a transition from a centralized to a distributed generation paradigm. In fact, power injection from Distributed Energy Resources (DERs) can be selectively controlled to achieve other objectives beyond supporting loads, such as the minimization of the power losses along the distribution lines and the subsequent increase of the grid hosting capacity. However, these technical achievements are only possible if alongside electrical optimization schemes, a suitable market model is set up to promote cooperation from the end users. In contrast with the existing literature, where energy trading and electrical optimization of the grid are often treated separately or the trading strategy is tailored to a specific electrical optimization objective, in this work we consider their joint optimization. Specifically, we present a multi-objective optimization problem accounting for energy trading, where: 1) DERs try to maximize their profit, resulting from selling their surplus energy, 2) the loads try to minimize their expense, and 3) the main power supplier aims at maximizing the electrical grid efficiency through a suitable discount policy. This optimization problem is proved to be non convex, and an equivalent convex formulation is derived. Centralized solutions are discussed first, and are subsequently distributed. Numerical results to demonstrate the effectiveness of the so obtained optimal policies are then presented.