You will need to set some concepts straight.
A GUI is a graphical user interface. It is where applications are controlled by interacting with windows, dialog boxes etc. drawn as bitmap graphics on the screen. Your terminal emulator also is a GUI program that is graphically painted on the screen.
The alternative is the console. This is a text prompt, rendered on a screen that only can display characters on specific locations (a "grid") on the screen. If you hit Ctrl+Alt+F4 you will be transferred to a text console, where you could log in. (With Alt+F2, you return to your graphical session).
You will be best served with a tiling window manager for your use case and considering your system is low in resources. A tiling window manager requires little resources to present you with a graphical user interface compared to a full blown desktop environment. Using Openbox is also an option: that is a floating window manager. Even using a lightweight desktop environments like LXQT, or a bare minimum XFCE setup, would cut it except if your machine is really resource limited (but then, it must be very, very old).
You could, like Richard Stallman, the founder of the Free Software movement, work off a text console. That would work perfectly for your work on Latex document and data analysis/machine learning/programming. However, as soon as you want to see a rendered document, or want a graphical browser, you would need to start the X server. If you need to do that occasionally, then the overhead that involves can be OK. If you need that more frequently, then the overhead will not be worth it, and for practical purposes, a lightweight graphical environment allow you to work fine even on less powered machines.
Is there a solution where I could have both GUI (just in case something goes wrong) and a window manager, so I can switch between them whenever I want?
On a standard version of Ubuntu (also flavors like Kubuntu or Xubuntu, etc) you can install additional desktop environments and/or window managers. Then, during login, you can select on what desktop or window manager you can log in. The choice is remembered until you change it again. So you can just keep your standard desktop as a backup, while you usually log in on for example a tiling window manager.
i3
(sudo apt install i3
) Screenshots: i3wm.org/screenshots