I just noticed an article in the CodeProject which offers "a fast algorithm to pack a series of rectangles of varying widths and heights into a single enclosing rectangle, with no overlap and in a way that minimizes the amount of wasted space in the enclosing rectangle". It appears to seek the smallest rectangle that will enclose a given set of rectangles. That's not quite the same as OP asks but I think it must be worth looking at.

Here's the link: Fast Optimizing Rectangle Packing Algorithm for Building CSS Sprites

BB