Conclusion first. The kinetic energy and potential energy of a small string segment of length $\Delta x$ are defined as $$ E_{kin}=\frac12 \rho \Delta x y_t^2 \\ E_{pot}= \frac12 T_0 \Delta x y_x^2 $$ Where $\rho$ is the linear density of the string (mass/length), $T_0$ is the tension on the string at rest. We have assumed small displacements. $y_t$ and $y_x$ are partial derivatives of $y(x,t)$ with respect to $x$ and $t$.
We can also divide both energy by the segment length $\Delta x$ and get kinetic energy density and potential energy density. $$ K.E(x,t) = \frac12 \rho y_t^2 \\ P.E(x,t) = \frac12 T_0 y_x^2 $$ Add them together, we have the energy density of the string: $$ E(x,t)=K.E(x,t)+P.E(x,t)= \frac12 \rho y_t^2 + \frac12 T_0 y_x^2 $$ We can integrate over length L and obtain the total energy of the string: $$ E_{string} = \int_0^L E(x,t) dx $$
Now to explain how to get kinetic energy and potential energy of a string. Each small $\Delta x$ segment is associated with two activities, oscillating verticallyoscillating vertically and stretching its lengthstretching its length. The formeroscillation contains kinetic energy $1/2 m v^2$$1/2 m v_y^2$, where $m = \rho \Delta x$ and $v_y=y_t$. The stretching contains potential energy, which is of the form $F\cdot \Delta L$. Here $F=T_0$ is a constant force along the string, $\Delta L$ is: $$ \Delta L = \sqrt{\Delta x^2 + \Delta y^2} - \Delta x = \Delta x (\sqrt{1+y_x^2} - 1) \approx \frac12 y_x^2 \Delta x $$