In general, beep codes are used in situations where video is not yet available or is unusable by the system at the point in time when a critical problem must (because the boot process cannot continue) be reported. In practice, there are a few cases where perhaps it would be possible to initialize video and display an error message, but it is still easier to just emit a beep code.
Common cases that can cause beep codes to be emitted are certain types of CPU problems (though I'm not sure how common this is in practice; particularly since ATX, it's perfectly possible that the system would simply refuse to do anything at all when you press the power button in that case), no graphics adapter, and RAM problems including no functional RAM installed.
Most firmware (BIOS, UEFI) emit a single short beep through the system's internal speaker at the end of the Power-On Self Test (POST), immediately before handing off control to the first stage of the operating system's bootloader. Unlike beep error codes, this comes much later (can easily be up to a few tens of seconds after power-on on systems with a number of peripherals connected), and it indicates that everything the POST checks checked out as working. Some allow this to be turned off through their built-in configuration utilities ("BIOS setup").
Beep codes are not normally emitted in the case of e.g. no monitor connected to the video output port (VGA, DVI, HDMI, ...) as that is not a critical error for the system itself. So-called "headless" systems run normally without any human input/output devices (monitor, keyboard, mouse) and are most often accessed over a network. Some firmware might emit a beep if a non-critical problem such as CMOS memory checksum error, no keyboard, etc. is detected, but that is a simple attention signal, not an error code like the beep codes.
Also note that beep error codes are motherboard-specific. You must refer to the reference for your particular type of motherboard to know what a particular error code means. There is usually a listing in the user's manual for the motherboard describing the various combinations.