Start with the Stefan-Boltzmann law, which gives you luminosity as a function of temperature $T$ and radius $R$:
$$L=4\pi R^2 \sigma T^4$$
where the units of luminosity are W/m^2. This luminosity is integrated over all solid angle and over the entire EM spectrum, so, to find the flux passing through a certain detector of area $a$, we must multiply $L$ by the fraction of the total solid angle taken up by the detector*:
$$F = 4\pi\frac{a}{4\pi D^2}L=\frac{a}{D^2}L$$
which is where the inverse-square law comes in. This is the bolometric flux (i.e. it's still integrated over the entire EM spectrum), so to obtain the flux in a particular band, you must multiply by the blackbody spectrum intensity $I(\lambda,T)$ for the detector's particular wavelength bandwidth $d\lambda$:
$$F_{\lambda,d\lambda} = I(\lambda,T)d\lambda\frac{a}{D^2}L$$
Apparent bolometric magnitude is defined as:
$$m=-2.5\log_{10}\left(\frac{F}{F_0}\right)$$
where $F_0$ is a particular standard bolometric magnitude. Likewise, for magnitude in a particular band, we have:
$$m_{\lambda,d\lambda}=-2.5\log_{10}\left(\frac{F_{\lambda,d\lambda}}{F_{0_{\lambda,d\lambda}}}\right)$$
where $F_{0_{\lambda,d\lambda}}$ is the analogous magnitude standard.
*This assumes that the flux is isotropic, i.e. it doesn't depend on direction.