  Merging binaries consisting of two neutron stars (NSs) or an NS and a
stellar-mass black hole typically form a massive accretion torus around the
remnant black hole or long-lived NS. Outflows from these neutrino-cooled
accretion disks represent an important site for $r$-process nucleosynthesis and
the generation of kilonovae. We present the first three-dimensional,
general-relativistic magnetohydrodynamic (GRMHD) simulations including weak
interactions and a realistic equation of state of such accretion disks over
viscous timescales ($380\,\mathrm{ms}$). We witness the emergence of
steady-state MHD turbulence, a magnetic dynamo with an $\sim\!20\,\mathrm{ms}$
cycle, and the generation of a `hot' disk corona that launches powerful thermal
outflows aided by the energy released as free nucleons recombine into
$\alpha$-particles. We identify a self-regulation mechanism that keeps the
midplane electron fraction low ($Y_e\sim0.1$) over viscous timescales. This
neutron-rich reservoir, in turn, feeds outflows that retain a sufficiently low
value of $Y_e\approx 0.2$ to robustly synthesize third-peak $r$-process
elements. The quasi-spherical outflows are projected to unbind $40\%$ of the
initial disk mass with typical asymptotic escape velocities of $0.1c$, and may
thus represent the dominant mass ejection mechanism in NS-NS mergers. Including
neutrino absorption, our findings agree with previous hydrodynamical
$\alpha-$disk simulations that the entire range of $r$-process nuclei from the
first to the third $r$-process peak can be synthesized in the outflows, in good
agreement with observed solar system abundances. The asymptotic escape
velocities and the quantity of ejecta, when extrapolated to moderately higher
disk masses, are consistent with those needed to explain the red kilonova
emission following the NS merger GW170817.
