Nonequilibrium thermodynamics of the spin Seebeck and spin Peltier effects