In the manual, browse through the top level table of content. You're interested in windows, so go to the chapter on windows. Browse through its table of contents until you find “Saving and restoring the state of the screen”, which is the section window configurations. Now you know how Emacs calls what you're looking for and you know what functions are ...
Define a function similar to the one that you want, but save the current frame configuration in some variable:
(defvar my-pre-agenda-frame-configuration nil)
(defun org-agenda-show-agenda-and-todo (&optional arg)
(setq my-pre-agenda-frame-configuration (current-frame-configuration))
(org-agenda arg "n"))
Then define a ...
You can save the current window configuration (as well as other features of your current Emacs session) using M-x desktop-save.
As node Saving Emacs Sessions of the Emacs manual tells you:
You can also enable automatic saving of the desktop when you exit Emacs, and automatic restoration of the last saved desktop when Emacs starts: use the Customization ...
You could try psession package. I find it fills exactly my needs.
In your init file :
;; For saving minibuffer history, as a replacement of savehist-mode.
;; to save periodically (autosave) your emacs session,