Derailleurs don't care if you have a freewheel or cassette. Also, you don't have to buy a Shimano freewheel; all modern freewheels will be inter-changeable in their threading/usage (most likely you will end up with a Sunrace or random Chinese one, anyway).
You have several parameters when you buy a rear derailleur (aside from things like direct mount vs non direct mount for getting the derailleur on the bike); these specs are on the info sheet for the derailleur:
Max/min cog (gears in back) sizes (self explanatory)
Derailleur capacity (how much slack the derailleur can take up in the chain); the necessary capacity depends on the cog and chainring sizes; the necessary capacity is (largest chainring - smallest chainring) + (largest cog - smallest cog)
Compatibility with the shifter (with an 8 speed shimano setup, you can use <=9 speed Shimano mountain derailleurs/ <=10 speed Road derailleurs)
Derailleurs are sold in short/medium/long cage versions, with higher capacity as the cage length increases.
Changing gearing may also necessitate adjusting the derailleur and replacing the chain (on length grounds, though most people coincide cassette+chain replacements anyway).
If the parameters above fit (cog size, capacity; since your derailleur is already mounted and working with the shifter), you just need to do adjustments. If not, you'll probably end up buying a long cage Shimano mountain derailleur which is 8 or 9-speed.