When are W-bosons emitted?

The reason for this is the so-called weak interaction (see Wikipedia - Weak interaction - Interaction types.

With very low probabilities (that's why it is named "weak") it causes reactions for example like these:

$$d \to u + W^- \tag{1}$$ $$u \to d + W^+ \tag{2}$$ $$d + W^+ \to u \tag{3}$$ $$u + W^- \to d \tag{4}$$ $$W^- \to e^- + \overline{\nu}_e \tag{5}$$ $$W^+ \to e^+ + \nu_e \tag{6}$$

The $W$ bosons are very heavy. Their rest mass is $80\ \mathrm{GeV}/c^2$. Therefore they cannot be created as permanently existing particles from reaction (1) or (2). That would violate the conservation of energy (including the rest mass energy $mc^2$).

But according to Heisenberg's uncertainty relation $\Delta E \Delta t \geq \hbar/2$ they are allowed to exist for $\approx 10^{-25}\ \mathrm{s}$ as virtual particles. And then they must disappear again through reaction (3), (4), (5) or (6). Actually this is not even enough time for them to leave the nucleon (proton or neutron) where they have been created, and so they get destroyed within that same nucleon.

Therefore a $W$ creating reaction can only happen combined with a $W$ destroying reaction $\approx 10^{-25}\ \mathrm{s}$ later.
By combining reactions (1) and (5) you get $\beta^-$ decay: $n \to p + e^- + \overline{\nu}_e$
By combining reactions (2) and (6) you get $\beta^+$ decay: $p \to n + e^+ + \nu_e$
By combining reactions (1) and (4) you get no change at all, also by combining (2) and (3).