We are going to introduce a new coordinate system $x'Oy'$ like shown in Fig. 1. If we are able to calculate coordinates of point $P(x'_P, y'_P)$ in that coordinate systen - we are done because:
$$x_O=-x'_P, \ \ y_O=-y'_P\tag{1}$$
Step 1:
Find coordinates of points $A,B,C,D$ in $x'Oy'$ coordinate system:
$$A: x'_1=d_1\cos\alpha, \ y'_1=d_1\sin\alpha$$
$$D: x'_2=d_4\cos(\alpha+90^\circ), \ y'_2=d_4\sin(\alpha+90^\circ)$$
$$B: x'_3=d_3\cos(\alpha+180^\circ), \ y'_3=d_3\sin(\alpha+180^\circ)$$
$$C: x'_4=d_2\cos(\alpha+270^\circ), \ y'_4=d_2\sin(\alpha+270^\circ)$$
Step 2:
Calculate the following values:
$$x'_{\min}=\min(x_1, x_2, x_3, x_4)$$
$$x'_{\max}=\max(x_1, x_2, x_3, x_4)$$
$$y'_{\min}=\min(y_1, y_2, y_3, y_4)$$
$$y'_{\max}=\max(y_1, y_2, y_3, y_4)$$
Step 3:
Find the bottom left corner $P'(x'_{P'}, y'_{P'})$ of the bounding rectangle (shown in blue color) and calculate the width $w$ and height $h$ of the bounding rectangle:
$$x'_{P'}=x'_\min$$
$$y'_{P'}=y'_\min$$
$$w=x'_\max-x'_\min$$
$$h=y'_\max-y'_\min$$
Step 4:
If $h=w=L$ we are done (see Fig. 2) because the blue rectangle is actually our bounding square of length $L$, the points $P$ and $P'$ are identical and $x'_{P}=x'_{P'}$, $y'_{P}=y'_{P'}$. Just apply (1) and you have $x_O, y_O$.
Step 5:
Needed only if $w<L$. In this case your blue rectangle is narrower than the square and it is possible that points $P$ and $P'$ are not identical. In other words, you have to expand the blue rectangle either to the left or to the right to match the original square.
If the blue rectangle has to be expanded to the right, it won't impact the position of point $P'$ and in this case:
$$x'_P=x'_{P'}$$
The point $P'$ moves only if you have to expand your rectangle to the left. Such situation is presented in Fig. 3. Obviously:
$$x'_P=x'_{P'}-(L-w)$$
Now apply (1) and you have $x_O$.
How to recognize that expansion to the left is needed? Take a look at Fig. 3 again. You cannot move the right side of the blue rectangle more to the right because that side has points $A$ and $C$ on it and that points are not corners. If you moved that side to the right, endpoints of $d_1$ and $d_2$ would be no longer "attached" to the right side. On the contrary, there is no non-corner point on the left side of the blue rectangle so you can freely move the left side further to the left and still have endpoints $A,B,C,D$ "attached" to sides of the square.
You can detect if there is a point $(x_i, y_i)$ on the left side of the blue rectangle that is blocking expansion to the left with the following condition:
$$x_i=x_\min \ \land \ y_i \ne y_\min \ \land \ y_i \ \ne y_\max$$
Expansion to the left is not possible if this condition is satisfied for any $i=1,2,3,4$
Step 6:
Needed only if $h<L$. In this case your blue rectangle is shorter than the square and it is possible that points $P$ and $P'$ are not identical. In other words, you have to expand the blue rectangle either upwards or downwards to match the original square.
If the blue rectangle has to be expanded upwards, it won't impact the position of point $P'$:
$$y'_P=y'_{P'}$$
The point $P'$ moves only if you have to expand your rectangle downwards. Such situation is presented in Fig. 1. Obviously:
$$y'_P=y'_{P'}-(L-h)$$
Now apply (1) and you have $y_O$.
How to recognize that expansion downwards is needed? Take a look at Fig. 1 again. You cannot move the top side of the blue rectangle upwards because that side has point $D$ on it and that point is not a corner. If you moved that side upwards, endpoint of $d_4$ would be no longer "attached" to the top side. On the contrary, there is no non-corner point on the bottom side of the blue rectangle so you can freely move the bottom side further down and still have endpoints $A,B,C,D$ "attached" to sides of the square.
You can detect if there is a point $(x_i, y_i)$ on the bottom side that is blocking expansion downwards with the following condition:
$$y_i=y_\min \ \land \ x_i \ne x_\min \ \land \ x_i \ \ne x_\max$$
Expansion downwards is not possible if this condition is satisfied for any $i=1,2,3,4$
Important note
Steps shown above can be transformed into a fairly simple and efficient software code. However, have in mind that your sensors have limited precision so something that is strictly equal in mathematics (like $L=w$) is just approximately equal in the real world. In the real world, $L$ will be always different from $w,h$ because we calculate the last two values from sensor readings.
So if you want to check if $L=w$, your code should actually test for:
$$|L-w|<\delta$$
...where $\delta$ is some small value adjusted for the precision of your sensors.
Best Answer
You basically have the right idea. The diagram above represents the bottom sensors, with the one on the left indicating a distance of $d1$ and the one on the right indicating a distance of $d2$. Add the labels shown, and the line $DC$ which is parallel to the line $AB$. Note that $ABCD$ is a rectangle, so $\angle DCE = 90^{\circ}$. Also, I believe you want to determine $\angle CDE$ as being the angle the robot is making wrt to the bottom wall. If so, then using the $\triangle DCE$, you have
$$\tan(\angle CDE) = \frac{d2 - d1}{200} \implies \angle CDE = \tan^{-1}\left(\frac{d2 - d1}{200}\right) \tag{1}\label{eq1A}$$
Based on my understanding of what you mean by the angle wrt the wall, the result from \eqref{eq1A} also gives the angle of the robot compared to the right wall.