My main problem is the following. I would like to put the problems and their solutions together into separate input files. In the source code I would like to switch easily between two modes. In mode 1 the solution of a problem follows the problem itself. In mode 2 there is a separate chapter for solutions at the end of the book. It is possible to solve this problem with the usage of a short predefined command between the problem and the solution in each input files and nothing else?
exsheets meets all your requirements.
You have two environments, 'question' and 'solution '. You can choose whether you want to print the answers and where. You can give IDs and include from external files by them. The appearance is very customizable.
Have a look into the documentation: http://mirrors.ctan.org/macros/latex/contrib/exsheets/exsheets_en.pdf