In this paper, we explore how to design the optimal insurance contracts when the insured faces insurable, counterparty, and additive background risk simultaneously. The target is to minimize the mean-variance of the insured’s loss. By utilizing the calculus of variations, an implicit characterization of the optimal ceded loss function is given. An explicit structure of the optimal ceded loss function is also provided by making full use of its implicit characterization. We further derive a much simpler solution when these three kinds of risk have some special dependence structures. Finally, we give a numerical example to illustrate our results.