We study the problem of finding optimal strategies for a life insurance company or pension fund that acts on behalf of an insured so as to maximize the expected utility (in a general form) of the pension benefits through dividend allocation and investment in a financial market. We take the uncertain course of life of the insured into account and provide the full picture of the policy's financial impact on the company. The policy risk is non-hedgeable, but apart from that the market is assumed to be complete. Our framework is quite general and allows for various specifications of interest, in particular also "purely" financial ones. We propose a two-step approach to the optimization problem: We first treat the benefit optimization problem using the martingale technique based on a certain martingale meaure. The company is then left with a payment process that cannot be perfectly hedged (due to the policy risk). This, in turn, constitutes a different problem for which we d...