The big answer is: Have clear boundaries. Define yourself. This time is my life, for my goals. That time is for your life, and your goals. If I feel your goals and mine coincide to some degree, I will share with you some more of my time. I believe this is a reasonable approach nobody can possibly object to (unless they are a cunt).
In detail:
Keep your boss happy as long as you feel your boss is making reasonable demands. If you suspect otherwise, gauge for yourself. Take a look around you. How hard or long are your peers working for the same paycheque? If your workload matches their workload, you are earning what they are being paid. If your company is too small for you to HAVE peers, this is one of the perils of operating in a small business. Thus, you need to work out when to relay tasks to subordinates (i.e. when your workload outstrips your paid time, tell your boss you need more people. Note that, for any person, past a certain workload, their performance cannot physically go anywhere but down.).
Do the work, the whole work, and nothing but the work for the hours you are paid to. If you have done it all, and you see no reason to put more work in (or make future work easier, like by improving code frameworks or whatever) then play. It’s hobby time baby.
Be friends with your boss, and know yourself. It’s important to know who you are and define yourself. What’s the goods, what’s the sucks, what’s the gap between them (and thus, what action shall you take), what are your goals (make one up if you don’t have one, remember?) etc. Be a robust system.
If your boss is cool, your job will feel better and most problems will automagically disappear. If your boss is a total prick, you’ll probably need to move on to a new job. Or, if you treasure your social connections you can a) take some people with you when you leave or bᅠ) get the boss kicked out by petitioning against your boss’s boss… and so forth until you reach the top. If the highest boss you can reach gives you the finger, you should probably move on to a new job. Either a) the company is doomed or bᅠ) you are making stupid demands
If your employer is a “well, at least LOOK like you’re working” type, then do so. Learn to switch windows fast. Get a window-hiding program. Learn those “boss key” shortcuts. This is placation, sure, but it works. (It’s not ass-kissing, it’s camouflage.)
Still stressed? Then get out there, online, and apply for other jobs (helps if you’re using an encrypted communication channel if you’re doing it on their net access). Socialise, connect. Improve your life, nobody else will do it for you.
Know yourself. If knowledge is power, you will become self-powered.
You will be your own boss.