You may be able to adapt portions of my
Pentominos Solving Quine. It's currently brute-forcing a fixed set of twelve different pieces, but it wouldn't be hard to make it play with a set of identical pieces and report best near-solutions. See the link there to the pre-obfuscated version with full comments and POD.
If you're interested in using this code as a starting-point, but still need a little help, let me know.
--
[ e d @ h a l l e y . c c ]