What is cost function? It tells us, given w1 and w2 what is the minimum cost required to produce y.
So we should try to find minimum cost to produce y given w1 and w2.
In long run - x2 = y^2 + x1 - 2ysqrt(x1)
So cost C = w1.x1 + w2.x2 ; Substitute x2 here
Minimize C. This will give you cost function.