In the limit as Earth's field goes to zero, you could make an approximation that the bar magnet is just a simple dipole. You can find an equation if you look at this dipole moment link.
For a generic current source, the general equation one would use is the Biot-Savart law. For a generic magnetic moment, consult Jackson's E&M book on multipole moments and the Biot-Savart law (i.e., Chapters 4 and 5, 3rd Edition). If there is geometric symmetry, one can often simplify this (greatly) by using Stokes' theorem to simplify Ampère's law.
Inclusion of the Earth's field, ignoring any time or spatial variations, would just be a superposition of magnetic fields. First measure the background magnetic field (i.e., Earth's field), then measure the field of the general magnet. In equation form, I think you could just treat Earth's field as an external applied magnetic field (e.g., Chapter 5, Section 11 in Jackson's E&M book, 3rd Edition).