We introduce a measure for energetic efficiency of biological cilia acting individually or collectively and numerically determine the optimal beating patterns according to this criterion. Maximizing the efficiency of a single cilium leads to curly, often symmetric, and somewhat counterintuitive patterns. However, when looking at a densely ciliated surface, the optimal patterns become remarkably similar to what is observed in microorganisms like Paramecium. The optimal beating pattern then consists of a fast effective stroke and a slow sweeping recovery stroke. Metachronal coordination is essential for efficient pumping and the highest efficiency is achieved with antiplectic waves. Efficiency also increases with an increasing density of cilia up to the point where crowding becomes a problem. We finally relate the pumping efficiency of cilia to the swimming efficiency of a spherical microorganism and show that the experimentally estimated efficiency of Paramecium is surprisingly close to the theoretically possible optimum.