You will probably need an app that allows product combos or bundles to achieve this in an ongoing manner. You could set the initial quantities of the different combinations based on the lowest available quantity of each size top or bottom within each combination (in the example you cite, any combination with an XS bottom would be set to zero, and any combination with an XS top would be set to 3, unless, for example there were only 2 M size bottoms, and then the XS top/M bottom combo would be set to 2). However, you would have to manually update all of the combinations going forward with each purchase to ensure accurate inventory tracking.
If you created separate products for the tops and bottoms (but keep these individual product pages hidden on your site), then used a combo/bundle app to create a combo product, it would allow for individual inventory tracking for each piece.
A few options: