In the D40 there's a channel that rises up from the rear of the wheel guard and up to the corner of the tub at the front. Just make sure you put some rubber (like a door seal) over the sharp lip. That allows the cable to come in. You can run the cable down the inside of the chassis which will protect it, but you still need to put a suitable fuse close to the battery.
How do you intend to charge it? Are you using an isolator in the engine bay? If so, you need a fuse on the rear battery as well. If you're using a DC-DC or inverter+AC-DC charger in the tub you don't need to fuse the rear battery on the cable to the front (but obviously you still need fuses between the rear battery and the aux items you are using).
As for securing it, there are several ways. You could mount a pre-fabricated box in the tub and secure it to the tub or to the cargo rails. I made a box for mine above the guard and secured it to the side cargo rails. I do intend to remove it and make it larger - both slightly wider and longer.
Your tub isn't waterproof. There are holes in the front at the bottom at the cargo rails, at the top in the corners, the tailgate does not seal and there are gaps in front of where the tail lights mount. I wouldn't worry too much about using waterproof entry points - you could use grommets/glands to help reduce the ingress of water at that point, but there's no need to worry if you come up through the corner anyway.