You are given a fixed perimeter and are asked to maximize the triangle's area.
If instead you assume a fixed area and try to minimize the perimeter,
you will achieve the same shape (maximize the ratio of area to perimeter)
but at a (possibly) different size. Then just scale the figure up or down
until you have the desired perimeter.
If you draw an equilateral triangle, and then draw a rectangle around it so that one side of the rectangle runs along one side of the triangle, what figure do you get?
How can you make the rectangle's perimeter as small as possible?
Now what does the figure look like?
What is the perimeter of the rectangle?
I think you will find that the edge of the triangle coincides with the longer edge of the rectangle, not the shorter edge. It helps to have a clear picture of what you're doing before you start assigning names to variables, if you can.
That's how you can do the first part. For the second part, instead of putting one side of the triangle exactly on one side of the rectangle, you can try putting an angle $\theta$ between them.
For a given $\theta,$ make the rectangle's perimeter as small as possible.
What is the resulting figure?
What is the rectangle's perimeter as a function of $\theta$?
How do you minimize it?
You can also do the problem in the more straightforward way you suggest,
where $p = \frac12P$ (a fixed value) and the sides of the rectangle are $x$ and $p - x.$ You must still have a clear picture of what you're doing.
Since the choice of which side to label $x$ is arbitrary,
I would suggest starting the first part by first assuming $x$ is the length of the side of the rectangle that lies along one side of the triangle,
and then try to figure out whether this is the larger or smaller side of the rectangle. (Better still, just solve for $x,$ and that will tell you.)