If it helps, there are quite a few threads around the forum, primarily in the non-hubmotor-drive / middrive subforums, about using hubmotors as middrives. Some of them get pretty far into it, even modifying the motor itself for easier operation (like Crossbreak's thread where he modifies a geared hubmotor to drive the axle as an output shaft, instead of spinning the case). Others are pretty simple, like Rassy's that just passes the pedal chain "under" the freewheel instead of wrapping around it, so that the freewheel needs nothing to secure it; it's still driven in the direction that would tighten it.
If you use a DD (direct drive, not a geared) hubmotor, you can run it backwards, flipped left-to-right, and put the sprocket on the disc brake rotor mount instead of using a freewheel, and not have to worry about it loosening. Or you can use either kind of motor with the sprocket on the brake rotor mount and drive the left side of the pedals like the old StokeMonkey system did. (you use a rightside pedal / chainring set on the leftside, in addition to the one on the right; they make ones for the leftside of tandem bikes you can buy, or just use a regular rightside one (but the pedal may unscrew on those, and won't on the tandem ones).
If you want a motor freewheel, and you're using it in a way that it could unscrew, you can file a notch (keyway) in it's threaded area along with a similar one in the motor freewheel threads, and insert a key between them after it's threaded on. This has been done in a few threads around here so there should be pictures, but you can find the general idea with a regular internet image search on shaft keyway / key.
https://www.google.com/search?q=shaft+keyway+%2F+key&tbm=isch
Note that if you don't use a motor freewheel, and the system is setup so the motor and pedals share a chain path, then pedalling without power will have drag on the pedals (possibly a lot, depending on your gearing ratios and the motor winding and type).
Additionaly if you don't use a pedal freewheel, the motor will drive the pedals so you need to choose a gear ratio that makes the pedals spin at a rate similar to what you would pedal at; if it's too fast it will throw your feet off the pedals and possibly whack the back of your legs.
(like riding a tandem bike with a captain or a stoker that's faster/better than you, and not being synchronized).
Freewheels are not required, but they can be useful depending on your usage and circumstances. One of my original CrazyBike2 drivetrains used a powerchair motor driving the pedals from the left side (like the old Stokemonkey system which used a hubmotor for that), then the pedals output normally to the rear wheel. No freewheels in the system except at the rear wheel, so if my feet came off the pedals I'd get whacked in the calves. Also had a problem once with my pantleg getting eaten in the chainring, and I had to stop the motor and figure out how to get my torn pants out of the mess while I was stuck on the bike with my leg trapped against it.
(a freewheel might've let me manually reverse the chainring spin by hand and undo the tangle; it probably wouldn' have stopped it from happening in the first place)
You seem to have already done this part, but the gearing (sprocket sizes) you'll need to determine based on how fast the motor will spin (RPM), and how fast you need the wheel to spin, and any parts of the frame that may get in the way of the chain path--beyond that, use the largest sprockets you can on each end of the system, so that you get the most number of teeth engaged with the chain for best torque transfer and least chain/sprocket wear (and also less noise).
If you choose a motor that will spin at about the same RPM as your pedals would, at the battery voltage you'll be using it at, then you don't need a big gearing ratio between them, they can be about 1:1 (so a 40T on the motor and 40T on the pedals) and the motor will just provide more power (or all the power if you like) into the pedal drivetrain.