  We construct models of Einstein and $f(R)$ gravity with two scalar fields,
which admit analytical solutions describing time-varying dynamical black holes.
Their thermodynamics is investigated in the adiabatic approximation. In
addition to the Misner-Sharp-Hernandez quasilocal mass, we provide
time-dependent thermodynamical quantities, including the Hawking temperature,
Helmholtz free energy, entropy, and thermodynamical energy. The latter does not
always coincide with the Misner-Sharp-Hernandez mass at the horizon, although
they coincide in the static limit. For Schwarzschild-type (i.e.,
$g_{tt}g_{rr}=-1$) black holes in Einstein gravity, one of the two scalars is
always a ghost with negative kinetic energy. We show that this ghost can be
avoided in $f(R)$ gravity.
