How to find the market equilibrium by surplus maximisation when there is a consumer subside? Let's assume a market with linear demand and supply functions, let's say $Q_d = 20 - 4p$ and $Q_s = -4 +8p$ respectively.

We can easily find the market equilibrium by either setting $Q_d = Q_s$ (or $P_d = P_d$ in the inverse demand and supply functions) or by maximising the total surplus, as done in the following screenshot:



We can now add a subside to the consumers, let's say 2 monetary unit/quantity unit, and the result is to shift up the demand curve, so that the new equilibrium can be easily obtained setting for example the prices equal in the new apparent demand curve $Q_dsub = 28-4p$ and the supply curve, and we find equilibrium quantity with subside $Q^{*sub} = 52/3$, eq. price with subside for the producers $P^{*sub}_{S} = 8/3$ and eq. price for the consumers with subsides $P^{*sub}_{D} = 2/3$

The problem is that if I try to obtain that results by maximisation of the total surplus as before, I obtain:

$$TotalSurplus = - \frac{3}{16}Q^2+\frac{9}{2}Q + P^{*sub}_{S} * Q^{*sub} - P^{*sub}_{D} * Q^{*sub}$$

When I account for $P^{*sub}_{S} = P^{*sub}_{D} + 2$, I obtain:

$$TotalSurplus = - \frac{3}{16}Q^2+\frac{9}{2}Q  + 2 * Q^{*sub}$$

And here I don't know how to continue, as the equilibrium point doesn't write off any more.
never work on weekends :-)

What you really do here is to find the total surplus in terms of $Q*$ and then maximise it setting the derivative to $Q*$ equal to zero.
So, you just maximise 
$$TotalSurplus = - \frac{3}{16}Q^{*2}+\frac{9}{2}Q^{*}  + 2 * Q^{*}$$
for $Q*$ and you obtain the expected results.