The cellular world is inhabited by a myriad of microorganisms able to self- propel, including many bacteria, spermatozoa, ciliates, and plankton. Here, we focus on the biophysics of ciliary locomotion. Cilia are short slender whiplike appendages (a few microns long, one tenth of a micron wide) internally actuated by molecular motors (dyneins) which generate a distribution of bending moments along the cilium length and produce time- varying shape deformations. In most cases cilia are not found individually but instead in densely packed arrays on surfaces. In this talk we will ask the question: can the individual and collective dynamics of cilia on the surface of an individual microorganism be rationalized as the solution to an optimization problem? We first address the deformation of individual cilia anchored on surfaces before characterizing the locomotion and feeding by surface distortions of swimmers covered by cilia array. We demonstrate, as solution to the optimization procedure, the appearance of the well-known two- stroke kinematics of an individual cilium, as well as waves in cilia array reminiscent of experimentally-observed metachronal waves.