Gutzwiller density functional theory: a formal derivation and application to ferromagnetic nickel