How to remove background HDR of rendered image using compositing?
The best way does not use compositing, but avoiding having a background image in the first place.

You would just go to Properties panel > Render tab > Film  and check Transparent.



By doing that your background will not be part of the render image and will be transparent through an Alpha channel:


Transparent enabled on the right



That being said, there is a way to do it using the following Compositing Nodes setup.



The Color Key takes out the black from the Environment pass. The Invert changes the matte map to preferable colors. The Alpha Over node actually adds the transparency.

The following .blend file is the one shown in the above Compositing Nodes screenshot.