What are the (immediate) effects of changing a good's price on consumer and producer surplus? Basically, I'm trying to understand why the total surplus is maximized at the equilibrium and what happens if the price isn't at the equilibrium. 

Say the price of a good is the equilibrium price. Now make it more expensive. I know that after a while the price will adjust to the equilibrium again, but what will happen before that? I'm trying to use an example but there are things I can't fill in:

The equilibrium price of the good is \$20 and the equilibrium quantity is 20. Given a straight demand and supply curve and a maximum buyer's imposed value of \$40, the consumer surplus is $\frac{1}{2}(40-20)\cdot20=200$ and the producer surplus is $\frac{1}{2}(20-0)\cdot20=200$.

Now make the good \$30. The quantity demanded falls to 15 and the quantity supplied rises to 25. Now, the consumer's surplus is the triangle I marked in blue, $\frac{1}{2}(40-30)\cdot15=75$ (because only 15 items will be sold), but what about the producer's surplus? Is this the triangle I marked in red? I think not, because that seems to imply that the price is only \$10. But if not, what is the producer's surplus, and why?



Thanks in advance and my apologies for the possibly confusing phrasing.
What is CS and PS out-of-equilibrium at $P=30$:
I think that answer to this question lies in misunderstanding the definition's of consumer and producer surplus.
The consumer and producer surplus are actually (following Mankiw Principles of Economics, 8th  ed, pp 135 and 140

consumer surplus:
the amount a buyer is
willing to pay for a good
minus the amount the
buyer actually pays for it


producer surplus
the amount a seller is
paid for a good minus the
seller’s cost of providing it [where Mankiw later in chapter explicitly states cost is here to be interpreted broadly as &quot;the value of everything
a seller must give up to
produce a good&quot;, including the opportunity cost (or more broadly s wilingness to sell)].

You will note that the definitions above talk about price people pay (i.e. actual market price) not 'equilibrium price'. Some lecture notes or textbooks will include the word equilibrium in the definitions but that is only because virtually all analysis using Supply-Demand is an analysis of some equilibrium.
More rigorously, since the maximum willingness to buy is bounded by the demand curve and willingness to sell by supply curve we can define consumer surplus as the area below the demand curve and above price paid by consumers and
$$CS =  \int^{q_m}_0 D(q) dq − p_mq_m $$
where $D(q)$ is arbitrary demand curve, $p_m$ is price consumers have to pay in the market, and $q_m$ quantity sold at the market.
$$PS =  p_mq_m - \int^{q_m}_0 S(q) dq $$
wher $S(q)$ is some arbitrary supply curve (also if we would want to be even more general we could allow $p$ to be different for suppliers and consumers e.g. situations with taxation where there would be wedge between price consumers pay and price per quantity suppliers get due to the tax wedge).
Yes, in some chapters or lecture notes the above formula will be defined in terms of equilibrium price but that is only because the market price/quantity is the equilibrium price/quantity in any equilibrium analysis (i.e. in equilibrium $p_e = p_m, q_m=q_e$).
However, in an out-of-equilibrium analysis you have to use actual market prices (this would be equivalent of analyzing price floor or price celling (e.g. see Mankiw Principles of Microeconomics, 8th  ed, pp. 116).
Consequently, in your case the consumer and producer surplus can be properly visualized as shown on the tikz graph below I made:

where the area of consumer surplus (out-of-equilibrium) at price $P_m=30$ is the blue shaded region below demand and above market price bounded by market quantity, and the producer surplus (out-of-equilibrium) at price $P_m=30$ is the red trapezoid (area under the market price and above supply bounded by market quantity).
We can also calculate the area of that trapezoid, although to do that we need to know what is the price at which $Q_S=0$ (or explicitly know what the supply and demand equations are). In your question you don't state what the  price at which supply is equals zero is but if you would provide it we could calculate it (also you seem to have made some mistake when copying down the problem as your demand does not lie on a line since it is given by points $(0,40);(15,30);(20,20)$ - which simply mathematically cannot lie on a single line - I originally planned to go all the way deriving the linear demand and supply equations based on the points but this mistake in problem set up makes it impossible ).
Why is total welfare maximized in equilibrium?
Well the reason for this is that under all the background assumptions of the stylized partial equilibrium model (e.g. no market failures and other 'shenanigans' that would affect PS and CS in way not shown in the partial equilibrium analysis here), the total combined area of PS and CS is maximized at the equilibrium price and quantity.
I won't be providing a rigorous proof of this as that would require a lot of calculus and this problem is long as it is, but I encourage you to take a look at proofs provided in MWG, Microeconomic analysis pp 328 or Varian, Microeconomic Analysis pp 224 if interested.
However, the reason why the welfare  be easily seen graphically by the following thought experiment: would the total surplus be larger if $P&gt;P_e$ or if $P&lt;P_e$? The answer is no as you can see visualized in the two figures below. As in both figures below the total surplus area will always fit within the big triangle given by area below demand and above supply clearly the total welfare is in both situations lower than the total welfare in a situation where $P_m=P_e$.


PS: An important caveat to note is that the above applies when you want to analyze what would be the total welfare outside equilibrium vs the welfare in equilibrium. If you want to compare two situations which are both equilibrium e.g. supply shifts to the right due to technological progress, you have to compare the total welfare in the market in the old equilibrium vs the new one. You should not confuse such situations with market not being in equilibrium.