This article presents a two-stage algorithm for piecewise affine (PWA) regression. In the first stage, a moving horizon strategy is employed to simultaneously estimate the model parameters and to classify the training data by solving a small-size mixed-integer quadratic programming problem. In the second stage, linear multicategory separation methods are used to partition the regressor space. The framework of PWA regression is adapted to the identification of PWA AutoRegressive with eXogenous input (PWARX) models as well as linear parameter-varying (LPV) models. The performance of the proposed algorithm is demonstrated on an academic example and on two benchmark experimental case studies. The first experimental example concerns modeling the placement process in a pick-and-place machine, while the second one consists in the identification of an LPV model describing the input-output relationship of an electronic bandpass filter with time-varying resonant frequency.