Many time series exhibit both nonlinearity and non-stationarity. Though both features have been often taken into account separately, few attempts have been proposed for modelling them simultaneously. We consider threshold models, and present a general model allowing for different regimes both in time and in levels, where regime transitions may happen according to self-exciting, or smoothly varying or piecewise linear threshold modelling. Since fitting such a model involves the choice of a large number of structural parameters, we propose a procedure based on genetic algorithms, evaluating models by means of a generalized identification criterion. The performance of the proposed procedure is illustrated with a simulation study and applications to some real data.