Your formula for cost looks correct. You need to take the derivative and set it equal to zero to find the minimum.
The second derivative test is used to determine if your answer is a minimum or maximum. In this case, it is obviously a minimum, so no second derivative test is required. Unless it's a second-derivative test exercise, of course.