In this paper we study necessary optimality conditions for the optimization problem $$\textrm{infimum}f_0(x) \quad \textrm{ subject to } \quad x \in S,$$ where $f_0 \colon \mathbb{R}^n \rightarrow \mathbb{R}$ is a polynomial function and $S \subset \mathbb{R}^n$ is a set defined by polynomial inequalities. Assume that the problem is bounded below and has the Mangasarian–Fromovitz property at infinity. We first show that if the problem does {\em not} have an optimal solution, then a version at infinity of the Fritz-John optimality conditions holds. From this we derive a version at infinity of the Karush–Kuhn–Tucker optimality conditions. As applications, we obtain a Frank–Wolfe type theorem which states that the optimal solution set of the problem is nonempty provided the objective function $f_0$ is convenient. Finally, in the unconstrained case, we show that the optimal value of the problem is the smallest critical value of some polynomial. All the results are presented in terms of the Newton polyhedra of the polynomials defining the problem.