We consider optimization problems involving convex risk functions. By employing techniques of convex analysis and optimization theory in vector spaces of measurable functions we develop new representation theorems for risk models, and optimality and duality theory for problems involving risk functions. Key words: Convex analysis, stochastic optimization, risk measures, mean-variance models, duality.