First thing first, let's go over some concept: heading is which way the plane's nose is pointing at, track is which way the plane is travelling on the ground. E.g. if your heading is 360 (North), and the wind is blowing from 090 (blowing East to West), the plane's track may be 350 (slightly left of North).
With that in mind, it's not hard to deduce most of the time pilots want to fly track, rather than heading. The purpose is to navigate from point A to point B on the ground. In our example, you have to turn the plane slightly to the right to compensate for the crosswind. To figure out exactly how many degrees to turn, you will first need to decide how fast you want to fly. After that, it's simple geometry.

A mechanical flight computer can be used to calculate the drift angle easily. Using it is a matter of marking dots on a transparent disc, then sliding and rotating it to the correct position and read off the pre-calculated figures below.

If you are flying manually, or flying a plane with an elementary autopilot, you will need to calculate the drift angle, then add (or minus) that to your desired track to get the heading. You will then set the heading bug to that value. Theoretically, that heading should compensate just enough crosswind that you stay on your desired ground track. In practice minor adjustments are often necessary. Provided that the numbers you use are not awfully off, you should end up with an estimation good enough for the safety of your flight.
If you are flying a plane with an advanced flight computer which has the ability to detect winds aloft, your autopilot will fly the track you dial in and automatically compensate for crosswind.
So to answer your questions:
You will use simple math or tools to compute the heading which will let you fly the desired track.
It does not matter when you have an exact headwind or tailwind.
Heading bug denotes the desired heading, not track. You always turn your plane towards the heading bug.
Advanced autopilot fly track, fundamental ones fly heading. Some autopilots can read the heading bug position on the instrument, others must be set explicitly on another panel.