As close as you like as long as the panel can be opened and the cover removed for service. Do not go too deep or it will be considered a cabinet and panels are not permitted in cabinets where stuff can be stored in front of the panel blocking it.
All responses based on the 2011 NEC.
If you live in New Jersey click here. All other states click here.
Please check with local, county and state officials as laws may vary.
Sizing motors here. Online motor calculator here. Online calculators here.