If its not been removed before (factory sponge sealer), its pretty easy. Undo all the retaining clips (remove the screws and they will come off). Once thats done, see how stuck down the window is (it may come off fairly easy). If not, get a stanley knife and begin to cut the foam sealer while gently pulling on the window toward you (i would start from the top of the hatch area first and work down to the bottom). You can also remove the trim inside the car and cut the sealer inside (just be careful and make sure the window wont drop ). Once the sealer is cut, it should come off.
To replace the foam, bunnings sell single sided glued foam rolls for sealing doors and joints. Its a little thicker than you need so cut the strip down the middle, peal back the tape and stick it to how the old one was applied on your window. On the non sticky side, apply some rubber/contact cement/adhesive and fix the window back to the car.