Hi Viswanath,
The spacing from the wall may depend a bit on exactly which standard you're pursuing.
In general GMP would suggest that there should be space to clean and allow for proper inspection behind anything stored near a wall, with 50cm being a common starting point.
We have used 50cm for years based on general GMP requirements, and this was perfectly acceptable for the OHSAS18001 certification we've just done.
The pallet stacking question is very dependent on exactly what you're stacking - packaging type, stacking pattern, weight, pallet type, wrapping/banding, use of any corner supports etc all have a significant impact, and you may therefore also find that the maximum safe/stable height could vary between different products. Some of our clients also set maximum heights for pallets (this varies between 1.2m and 1.6m) so you may also need to take this into account.
Sorry it's not an exact answer, but I'm not sure that is possible without a lot more detail.