Elastic energy release due to domain formation in the strained epitaxy of ferroelectric and ferroelastic films