In terms of ecology what is optimality?
Optimality theory

Optimality theory is a concept of linguistic. See wiki > Optimality theory. This is probably not what you were referring to.

What is optimality

Optimality is the condition under which something is maximized! In behavioural ecology, this something is often fitness and the condition is often measured in terms of magnitude/intensity of a behaviour.

Optimality models

In ecology, we call optimality model any model that separate the benefits and costs (in terms of some measurement, often fitness) of a given phenotype (often behaviour). By weighing benefits and costs one can figure out what is the optimal phenotype. The principle is extremely simple. Such graphs are quite standard:



In the graph, the X-axis represents the magnitude of a phenotype (often a behaviour) and the Y-axis represents the benefit and cost of this behaviour (with the same scale) often in terms of fitness.

By definition, the fitness is maximized when $B-C$ is maximized. In other words, compute B-C and look for the maximum (through derivation) and you found the optimal phenotype (often behaviour). In the above graph, the optimal phenotype is a little bit left to the position of the B label.

Optimal foraging theory

Foraging behaviour has been subject to much investigations using optimality models. We refer to this body of knowledge as Optimal foraging theory.