Your answer depends upon the details of your theme.
Look at your theme files and see how it assembles your website’s pages, in your theme folder you will likely have a file “header.php”, it will produce your “<head>” tag, and then call a hook function such as “afterhead();” (or similar), or maybe just “wp_head();”. See how it is defined, it will tell you how to add a function to this hook. Similarly after the “<body>” tag it calls “wp_body_open();”.
In each case find the hook that is invoked in that context. Now add functions to these hooks, could be done in a plugin, but more likely in the theme’s “functions.php” file, to do this properly you need to be working in a child theme, details here:
creating a child theme http://codex.wordpress.org/Child_Themes
if this does not suit you then this may help:
https://github.com/woothemes/theme-customisations
I have given specifics for the twentynineteen theme, the specifics may vary.