Algorithm to pack any small boxes into a big box
Your problem is called 3D Bin Packing and is indeed an NP problem. 

Looking those key words on Google will yield many articles about more or less complex approximation algorithms that can help you solve this problem.