Spatial localization and pattern formation in discrete optomechanical cavities and arrays