\(\(lag[k1_, k2_, i0_, i1_, i2_, l0_, l1_, l2_] := 
      u[f[bar_k0] - \ i0]\  + \ u[f[k1]\  - \ i1]/\((1 + r)\)\  + \ 
\ 
        u[f[k2]\  - \ i2]/\((1 + r)\)^2\  + \ \ 
        l0\ \((k1\  - \ bar_k0\  - \ i0)\)\  + \ 

        l1\ \((k2\  - \ k1\  - \ i1)\)\  + \ 
        l2\ \((bar_k3\  - \ k2\  - \ i2)\)\ \)\)

dk1 = D[lag[k1, k2, i0, i1, i2, l0, l1, l2], k1]

dk2 = D[lag[k1, k2, i0, i1, i2, l0, l1, l2], k2]

di0 = D[lag[k1, k2, i0, i1, i2, l0, l1, l2], i0]

di1 = D[lag[k1, k2, i0, i1, i2, l0, l1, l2], i1]

di2 = D[lag[k1, k2, i0, i1, i2, l0, l1, l2], i2]

dl0 = D[lag[k1, k2, i0, i1, i2, l0, l1, l2], l0]

dl1 = D[lag[k1, k2, i0, i1, i2, l0, l1, l2], l1]

dl2 = D[lag[k1, k2, i0, i1, i2, l0, l1, l2], l2]

?? Eliminate

Eliminate[{dk1 == 0, dk2 == 0, di0 == 0, di1 == 0, di2 == 0, dl0 == 0, 
        dl1 == 0, dl2 == 0}, {l0, l1, l2}]