Install rigid foam insulation on top of the sheathing and top with metal roofing panels for new construction. Butt the edges of the foam together and use screws to hold it in place, sealing all seams with duct tape to protect the edges from moisture damage. Insulate existing metal roofs by attaching the rigid foam to the bottom of the sheathing and filling any gaps with fiberglass insulation or using spray foam insulation.
Installing the insulation above the sheathing offers the advantage of eliminating any thermal breaks that occur when installing it under it due to the roof rafters. It also provides an additional layer of protection that protects the sheathing from water damage. The process reduces the amount of cutting and fitting for installation, but is only viable for new construction or when replacing the metal roof.
Adding rigid foam under the sheathing eliminates the need to remove the metal for an existing roof. However, you must cut the panels to fit the accessible spaces and attach it with staples or construction adhesive. Fill any gaps with fiberglass insulation, but avoid compressing the fiberglass, which makes it less effective.
Only apply spray foam insulation to the underside of metal roofs that have wood sheathing underneath. Without this layer, the foam can escape through the metal and cause significant damage.