On the connections between optimality conditions, variational inequalities and equilibrium problems