Stability and optimal control for some classes of tritrophic systems