ArturoP, as John said, instead of minimizing EV/EBIT, you could as well maximize the inverse ratio EBIT/EV, thus eliminating the division by 0.
You could think of the ratio (e.g. EBIT/EV) as a utility function, i.e. how well you evaluate a company based on the 2 variables, such as U(EBIT,EV) = EBIT/EV.
You'll notice that the ratio above works well when EBIT >= 0. But it is less intuitive when EBIT < 0, since presumably expansive non-profitable companies are the worst case. A workaround for that could be splitting your domain into 2, and define a negative utility as the example below:
\begin{align*}
W \sim U(EBIT,EV) = \begin{cases}
\frac{EBIT}{EV}, & \text{ if } EBIT >= 0\\
EBIT.EV, & \text{ if } EBIT < 0
\end{cases}
\end{align*}
So that your allocation weights W are somehow proportional to your utility.